package com.qianxx.component.activity.progress.seek_bar;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.SeekBar;

import com.qianxx.component.R;
import com.qianxx.component.activity.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SeekBarActivity extends BaseActivity {
    @BindView(R.id.seek_bar)
    SeekBar seek_bar;

    DownLoadThread mThread;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seek_bar);
        ButterKnife.bind(this);

        if(mThread == null){
            mThread = new DownLoadThread();
            mThread.start();
        }
    }


    private class DownLoadThread extends Thread{
        @Override
        public void run() {
            for (int i = 0; i <= 100; i++) {
                handler.sendEmptyMessage(i);
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private Handler handler = new Handler(){
        @Override
        public void dispatchMessage(Message msg) {
            int progress = msg.what;
            seek_bar.setProgress(progress);
        }
    };

    @Override
    public String setTitle() {
        return "SeekBar";
    }
}
